<?php
	class MessageAction extends BaseAction {
		
		public function list_message(){
			$cid = $_GET['cid'];
			$list = D('Message')->select_message($cid);	
			//print_r($list);
			$thispage = empty($_GET['p'])?1:$_GET['p'];
			$nextpage = $thispage+1;
			$uppage = $thispage-1;
			if($uppage<1){
				$uppage = 1;
			}
			$this->assign('uppage',U('Message/list_message/cid/{$cid}',array('p'=>$uppage)));
			$this->assign('nextpage',U('Message/list_message/cid/{$cid}',array('p'=>$nextpage)));		
			$this->assign("list",$list);
			$this->display();
		}


		public function add_mess(){
			if($this->isPost()){
		      $map['content'] = $_POST['content'];
		      $wei = $_POST['admin'];
		      $uname = D('user')->where(array('wx'=>$wei))->getField('uname');
		      if($uname == ""){
		      	 $map['from'] =  "微信用户";
		      }else{
		      	 $map['from'] =  $uname;
		      }
		      $map['to'] = $_POST['cid'];
		      $map['ctime'] = time();
	      	  $da = D('message')->add($map);
	      	  $url = "__URL__/list_message/cid/".$map['to'];
		      if($da){
		      	$return = array('status'=>1,'data'=>'提交成功');
		      }
	  		}
	  		exit(json_encode($return));
		}

		
	}
?>